package com.d2rv.settings;

import processing.core.PApplet;

/**
 * Describes the timer object used for a regular rendering with the Singleton
 * pattern
 *
 * @author Darrieutort A., Dupouy A., Rossignol L., Van Poucke A.
 */
public class FpsTimer {

    private static final FpsTimer instance = new FpsTimer();
    private PApplet parent;
    private int previoustime;
    private float coeffps;

    /**
     * Default constructor.
     */
    private FpsTimer() {
    }

    /**
     * Initializes the Timer
     *
     * @param parent the current application
     */
    public void init(PApplet parent) {
        this.parent = parent;
        this.previoustime = 0;
        this.coeffps = 0;
    }

    /**
     * Returns the timer instance.
     *
     * @return the timer instance
     */
    public static FpsTimer getInstance() {
        return instance;
    }

    /**
     * Computes the coefficient proportional to the fps rate.
     *
     */
    public void computeFps() {
        this.coeffps = (this.parent.millis() - this.previoustime);
    }

    /**
     * Sets the previous time to a new value.
     *
     * @param time the new value of time
     */
    public void previoustime(int time) {
        this.previoustime = time;
    }

    /**
     * Returns the current application.
     *
     * @return the current application
     */
    public PApplet parent() {
        return this.parent;
    }

    /**
     * Returns the fps coefficient.
     *
     * @return the fps coefficient
     */
    public float coeffps() {
        return this.coeffps;
    }
}